package org.component 
{
	import org.component.item.TabBarItem;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	import flash.utils.Dictionary;
	import org.component.events.TabBarEvent;
	import com.peachcastle.core.Display;

	[Event(name = "tabbar_select", type = "org.component.events.TabBarEvent")]
	
	public class TabBar extends Display
	{
		
		private var _tabs:Array = null;
		
		private var _colors:Dictionary = null;
		
		public function TabBar(ui:MovieClip = null) 
		{
			super(ui);
		}
		
		override protected function initialization():void 
		{
			super.initialization();
			
			_tabs = [];
			
			_colors = new Dictionary();
		}
		
		
		public function setColor(over:uint = 0xffffff, out:uint = 0xffffff, select:uint = 0xffffff):void
		{
			_colors["over"] = over;
			_colors["out"] = out;
			_colors["select"] = select;
		}
		
		public function addItem(ui:MovieClip = null,label:String = ""):void
		{
			var item:TabBarItem = new TabBarItem(ui);
			item.getSubject(this);
			if(label!="")item.label = label;
			_tabs[_tabs.length] = item;
			item = null;
		}
		
		private var _selectIndex:int = -1;
		
		public function get selectIndex():int { return _selectIndex; }
		
		public function set selectIndex(value:int):void
		{
			_selectIndex = value;
			
			selectItem = _tabs[value];
		}
		
		private var _selectItem:TabBarItem = null;
		
		public function get selectItem():TabBarItem { return _selectItem; }
		public function set selectItem(value:TabBarItem):void
		{
			if (_selectItem == value) return;
			
			if (_selectItem)
			{
				_selectItem.select = false;
			}
			_selectItem = value;
			_selectItem.select = true;
			
			var evt:TabBarEvent = new TabBarEvent(TabBarEvent.TABBAR_SELECT);
			evt.item = _selectItem;
			dispatchEvent(evt);
			evt = null;
		}
		
	
		public function getIndexByItem(index:int):TabBarItem
		{
			return _tabs[index] as TabBarItem;
		}
		
		public function hideAll():void
		{
			for each(var tab:TabBarItem in _tabs)
			{
				tab.visible = false;
			}
		}
		
		public function showAll():void
		{
			for each(var tab:TabBarItem in _tabs)
			{
				tab.visible = true;
			}
		}
		public function get color():Dictionary { return _colors; }
		
	}

}